<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="back" @click="navigateBack">
        <uni-icons type="left" size="20" color="#fff"></uni-icons>
      </view>
      <view class="title">领券中心</view>
      <view class="right"></view>
    </view>
    
    <!-- 优惠券列表 -->
    <view class="bg"/>
    <view class="coupon-list">
      <view class="coupon-item" v-for="(coupon, index) in coupons" :key="index">
        <!-- 左侧金额 -->
        <view class="coupon-left">
          <text class="symbol">¥</text>
          <text class="amount">{{ coupon.amount }}</text>
        </view>
        
        <!-- 中间说明 -->
        <view class="coupon-center">
          <view class="condition">满{{ coupon.minAmount }}元可用</view>
          <view class="limit">仅限于{{ coupon.shopName }}使用</view>
          <view class="date">{{ coupon.startDate }}—{{ coupon.endDate }}</view>
        </view>
        
        <!-- 右侧按钮 -->
        <view class="coupon-right">
          <button 
            class="receive-btn" 
            :class="{ 'received': coupon.isReceived }"
            @click="receiveCoupon(coupon)"
            :disabled="coupon.isReceived"
          >
            {{ coupon.isReceived ? '已领取' : '领取' }}
          </button>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';

// 定义响应式数据
const coupons = ref([
  {
    amount: 20,
    minAmount: 200,
    shopName: 'XX加油站',
    startDate: '2020.04.11',
    endDate: '2023.05.11',
    isReceived: false
  },
  {
    amount: 20,
    minAmount: 200,
    shopName: 'XX加油站',
    startDate: '2020.04.11',
    endDate: '2023.05.11',
    isReceived: true
  }
]);

// 定义方法
const navigateBack = () => {
  uni.navigateBack();
};

const receiveCoupon = (coupon) => {
  if (coupon.isReceived) return;
  
  // 这里可以添加领取优惠券的API调用
  uni.showLoading({
    title: '领取中...'
  });
  
  setTimeout(() => {
    uni.hideLoading();
    coupon.isReceived = true;
    uni.showToast({
      title: '领取成功',
      icon: 'success'
    });
  }, 1000);
};
</script>

<style lang="scss" scoped>

.bg{
		width: 100%;
		height: 250rpx;
		background-color: #007aff;
	}
.container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.nav-bar {
  display: flex;
  align-items: center;
  height: 44px;
  background-color: #007AFF;
  color: #fff;
  padding: 0 15px;
  
  .back {
    width: 44px;
  }
  
  .title {
    flex: 1;
    text-align: center;
    font-size: 18px;
  }
  
  .right {
    width: 44px;
  }
}

.coupon-list {
	margin-left: 10px;
	margin-right: 10px;
	margin-top: -200rpx;
	border-top-right-radius: 20px;
	border-top-left-radius: 20px;
  padding: 15px;
  
  .coupon-item {
    display: flex;
    align-items: center;
    background-color: #fff;
    border-radius: 8px;
    margin-bottom: 15px;
    padding: 15px;
    position: relative;
    overflow: hidden;
    
    &::before {
      content: '';
      position: absolute;
      left: -4px;
      top: 50%;
      transform: translateY(-50%);
      width: 8px;
      height: 8px;
      background-color: #f5f5f5;
      border-radius: 50%;
    }
    
    &::after {
      content: '';
      position: absolute;
      right: -4px;
      top: 50%;
      transform: translateY(-50%);
      width: 8px;
      height: 8px;
      background-color: #f5f5f5;
      border-radius: 50%;
    }
  }
}

.coupon-left {
  width: 100px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  color: #FF6B35;
  padding-right: 15px;
  border-right: 1px dashed #eee;
  
  .symbol {
    font-size: 16px;
    margin-right: 2px;
  }
  
  .amount {
    font-size: 32px;
    font-weight: bold;
  }
}

.coupon-center {
  flex: 1;
  padding: 0 15px;
  
  .condition {
    font-size: 16px;
    color: #333;
    margin-bottom: 5px;
  }
  
  .limit {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
  }
  
  .date {
    font-size: 12px;
    color: #999;
  }
}

.coupon-right {
  width: 80px;
  
  .receive-btn {
    width: 70px;
    height: 30px;
    line-height: 30px;
    background-color: #FF6B35;
    color: #fff;
    font-size: 14px;
    border-radius: 15px;
    padding: 0;
    
    &.received {
      background-color: #ccc;
    }
    
    &:active {
      opacity: 0.8;
    }
  }
}
</style>